import { ApiCall } from "tsrpc";
import { ReqOpenBlindBox, ResOpenBlindBox } from "../../../../shared/master/bag/function/PtlOpenBlindBox";
import { player } from "../../../../model/fight/body/player";
import { Tpl_gifts_default, template } from "../../../../shared/master/MsgAction";
import app, { xlsxCfgNames } from "../../../../app";
import god from "../../../../god";
import { bag } from "../../../../model/bag/bag";
const useId = 'prop-2';

export default async function (call: ApiCall<ReqOpenBlindBox, ResOpenBlindBox>) {
    call.succ({})
    if (call.req.num <= 0) {
        call.req.num = 1;
    }
    let user = call.req._player as player;
    let res = user.check_wallet(0, 0, [{ id: useId, v: call.req.num }], false, '打开盲盒消耗', false);
    if (!res.state) {
        return;
    }
    // 根据盲盒总价值 给予相同价值的道具
    const item = app.getCfgData(useId)

    let needValue = app.random(item.value * call.req.num * 0.5, item.value * call.req.num * 1.2);
    let list = god.getRandomItems(needValue, `${user.name}·盲盒开启`, xlsxCfgNames.盲盒奖励配置,true);
    let tpl: Tpl_gifts_default = {
        title: `盲盒开启完成`,
        items: user.addItems(list)
    }
    user.sendMsg(template.通用奖励, tpl)

    

}